package com.yupi.oj.component;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;
import com.yupi.oj.codeBox.model.requesst.ExecuteRequest;
import com.yupi.oj.codeBox.model.response.ExecuteResponse;

/**
 * 代码沙箱调用组件
 *
 * @author yanghaifeng
 * @date 2024/6/5 09:49
 */
public class CodeSandBoxComponent {

    public static ExecuteResponse callCodeBox(ExecuteRequest executeRequest) {
        String body = JSONUtil.toJsonStr(executeRequest);
        HttpResponse response = HttpRequest.post("http://127.0.0.1:8090/codeBox/call").body(body).execute();
        String responseBody = response.body();
        return JSONUtil.toBean(responseBody, ExecuteResponse.class);
    }
}
